<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"  xmlns:c="http://java.sun.com/jsp/jstl/core">  

    <ui:composition template="layout.xhtml">
        <ui:define name="corpo">
            <h:form id="buscar_form" acceptcharset="utf-8"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexProtocolo.xhtml')}" value="Protocolo" update="@form" immediate="true"/> > 
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexLancamento.xhtml')}" value="Lançamentos" update="@form" immediate="true"/> >
                    <p:commandLink  value="Cadastrar" update="@form" immediate="true"/>
                </div>
                <p:panel header="Lançamentos">
                    <p:messages id="msg"/>

                    <fieldset>
                        <legend>Filtro</legend> 
                        <h:panelGrid columns="2" id="panelGridEscolha" styleClass="textAlignRight" columnClasses="textAlignRight">
                            <h:outputLabel value="Prestador:"/>
                            <p:autoComplete id="usuario" value="#{managerLancamento.usuario}" 
                                            completeMethod="#{managerUsuario.completeUsuario}"  
                                            var="p" itemLabel="#{p.nome}" itemValue="#{p}" 
                                            converter="usuarioConverter" forceSelection="true" 
                                            converterMessage="Erro, verifique o Fornecedor"
                                            minQueryLength="3" dropdown="true" required="true" 
                                            requiredMessage="O campo 'Usuario' é obrigatório"
                                            scrollHeight="200"/>
                            
                            <h:outputLabel value="Data :"/>
                            <p:calendar value="#{managerLancamento.lancamento.dataLanc}"
                                        mode="popup" showOn="both" pattern="dd/MM/yyyy"
                                        required="true" requiredMessage="O campo data é obrigatório"/>
                            
                        </h:panelGrid> 
                        <div class="buttonAction">
                            <p:commandButton value="Consultar" icon="ui-icon-search"
                                             actionListener="#{managerLancamento.buscar()}" 
                                             update="@form" />
                            
                            <p:commandButton value="Limpar" icon="ui-icon-closethick"
                                             actionListener="#{managerLancamento.clean()}" 
                                             update="panelGridEscolha" />
                        </div>
                        
                    </fieldset>
                    
                    
                    <fieldset class="#{managerLancamento.showLancamento ? '' : 'clear'}">
                        <legend>Lançamento</legend> 
                        <h:panelGrid columns="2" id="details" styleClass="detailsTables">
                            <p:column >
                                <p:dataTable id="protocoloTable" var="protocolo" value="#{managerLancamento.lancamento.protocolos}" 
                                             paginator="true" rows="5"
                                             paginatorPosition="bottom"
                                             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  
                                             rowsPerPageTemplate="5,10,15"
                                             emptyMessage="Nenhum Registro Encontrado">    

                                    <f:facet name="header">  
                                        Crédito
                                    </f:facet>

                                    <p:column style="width:15px;text-align: center">  
                                        <p:commandButton icon="ui-icon-search" oncomplete="dlgProtocolo.show();" update=":buscar_form:dlgProtocolo">
                                            <f:setPropertyActionListener target="#{managerLancamento.protocolo}" value="#{protocolo}" />
                                        </p:commandButton>
                                    </p:column>

                                    <p:column  style="width:40px;text-align: center">  
                                        <f:facet name="header" >   
                                            Código
                                        </f:facet>  
                                        <h:outputText value="#{protocolo.id}" style="font-weight: bold;"  />  
                                    </p:column>


                                    <p:column  style="width:100px;">  
                                        <f:facet name="header" >   
                                            Cartório
                                        </f:facet>  
                                        <h:outputText value="#{protocolo.valorTotalCartorio}" style="font-weight: bold;"  >
                                            <f:convertNumber pattern="#,###,##0.00"/>
                                        </h:outputText>    
                                    </p:column>

                                    <p:column  style="width:100px;">  
                                        <f:facet name="header" >   
                                            Fermojupi
                                        </f:facet>  
                                        <h:outputText value="#{protocolo.valorTotalFermojupi}" style="font-weight: bold;"  >
                                            <f:convertNumber pattern="#,###,##0.00"/>
                                        </h:outputText>    
                                    </p:column>



                                </p:dataTable> 

                                <h:panelGrid columns="2" styleClass="maisDetalhes">
                                    <h:outputLabel value="Valor cartório:" />
                                    <p:inputText value="#{managerLancamento.totalCartorio}" readonly="true" >
                                        <f:convertNumber pattern="#,###,##0.00"/>
                                    </p:inputText>
                                    <h:outputLabel value="Valor Fermojupi:" />
                                    <p:inputText value="#{managerLancamento.totalFermojupi}" readonly="true" >
                                        <f:convertNumber pattern="#,###,##0.00"/>
                                    </p:inputText>
                                    <h:outputLabel value="Total :" />
                                    <p:inputText value="#{managerLancamento.valorTotalProtocolo}" readonly="true" >
                                        <f:convertNumber pattern="#,###,##0.00"/>
                                    </p:inputText>
                                </h:panelGrid>
                            </p:column> 

                            <p:column>

                                <p:dataTable id="pagamentosTable" var="pagamento" value="#{managerLancamento.lancamento.pagamentos}" 
                                             paginator="true" rows="5"
                                             paginatorPosition="bottom"
                                             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  
                                             rowsPerPageTemplate="5,10,15"
                                             emptyMessage="Nenhum Registro Encontrado">    

                                    <f:facet name="header">  
                                        Débito
                                    </f:facet>


                                    <p:column  style="width:20px; text-align: center">  
                                        <p:commandButton icon="ui-icon-search" oncomplete="dlgPagamento.show();" update=":buscar_form:dlgPagamento">
                                            <f:setPropertyActionListener target="#{managerLancamento.pagamento}" value="#{pagamento}" />
                                        </p:commandButton>
                                    </p:column>

                                    <p:column  style="width:40px; text-align: center">  
                                        <f:facet name="header" >   
                                            Código
                                        </f:facet>  
                                        <h:outputText value="#{pagamento.id}" style="font-weight: bold;"  />  
                                    </p:column>

                                    <p:column  style="width:150px;">  
                                        <f:facet name="header" >   
                                            Titulo
                                        </f:facet>  
                                        <h:outputText value="#{pagamento.titulo}" style="font-weight: bold;"  />  
                                    </p:column>

                                    <p:column  style="width:50px;">  
                                        <f:facet name="header" >   
                                            Valor
                                        </f:facet>  
                                        <h:outputText value="#{pagamento.valor}" style="font-weight: bold;"  >
                                            <f:convertNumber pattern="#,###,##0.00"/>
                                        </h:outputText>   
                                    </p:column>


                                </p:dataTable> 
                                <h:panelGrid columns="2" styleClass="maisDetalhes">
                                    <h:outputLabel value="Total :" />
                                    <p:inputText value="#{managerLancamento.valorTotalPagamento}" readonly="true" >
                                        <f:convertNumber pattern="#,###,##0.00"/>
                                    </p:inputText>
                                </h:panelGrid>
                                '    </p:column>
                        </h:panelGrid>

                        <p:panel >
                            <f:facet name="header">
                                <h:outputLabel value="Resumo - "/>
                                 <h:outputLabel value="#{managerLancamento.lancamento.dataLanc}" style="font-weight: bold">
                                        <f:convertDateTime pattern="dd/MM/yyyy" />
                                    </h:outputLabel>
                            </f:facet>
                            <h:panelGrid columns="2" style="width: 100%"  styleClass="detailsTables" id="detailsTables">
                                <p:column>
                                   
                                    <div class="ui-datatable ui-widget">
                                        <table role="grid">
                                            <thead>
                                                <tr role="row">
                                                    <th class="ui-state-default" role="columnheader">
                                                        <div class="ui-dt-c">
                                                            <span> Protocolos</span>
                                                        </div>
                                                    </th>
                                                    <th class="ui-state-default" role="columnheader">
                                                        <div class="ui-dt-c">
                                                            <span>Pagamentos</span>
                                                        </div>
                                                    </th>
                                                    <th class="ui-state-default" role="columnheader" >
                                                        <div class="ui-dt-c">
                                                            <span>Selos</span>
                                                        </div>
                                                    </th>
                                                </tr>
                                            </thead>

                                            <tbody class="ui-datatable-data ui-widget-content">
                                                <tr data-ri="0" class="ui-widget-content ui-datatable-even" role="row">
                                                    <td role="gridcell">
                                                        <div class="ui-dt-c"><span style="font-weight: bold;">#{managerLancamento.qtdeProtocolos}</span></div>
                                                    </td>
                                                    <td role="gridcell" >
                                                        <div class="ui-dt-c"><span style="font-weight: bold;">#{managerLancamento.qtdePagamentos}</span></div>
                                                    </td>
                                                    <td role="gridcell" style="width:100px;">
                                                        <div class="ui-dt-c"><span style="font-weight: bold;">#{managerLancamento.qtdeSelos}</span></div>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>

                                </p:column>

                                <p:column>
                                    <h:panelGrid columns="2" styleClass="maisDetalhes">
                                        <h:outputLabel value="Crédito : " />
                                        <p:inputText value="#{managerLancamento.totalCredito}" readonly="true" >
                                            <f:convertNumber pattern="#,###,##0.00"/>
                                        </p:inputText>
                                        <h:outputLabel value="Débito: " />
                                        <p:inputText value="#{managerLancamento.totalDebito}" readonly="true" >
                                            <f:convertNumber pattern="#,###,##0.00"/>
                                        </p:inputText>
                                        <h:outputLabel value="À receber : " />
                                        <p:inputText value="#{managerLancamento.totalReceber}" readonly="true" >
                                            <f:convertNumber pattern="#,###,##0.00"/>
                                        </p:inputText>
                                        <h:outputLabel value="Receita : " />
                                        <p:inputText value="#{managerLancamento.totalReceita}" readonly="true" >
                                            <f:convertNumber pattern="#,###,##0.00"/>
                                        </p:inputText>
                                    </h:panelGrid>

                                </p:column>

                            </h:panelGrid>
                        </p:panel>

                    </fieldset>
                    <div class="buttonAction">
                        <p:commandButton value="Salvar" icon="ui-icon-disk" actionListener="#{managerLancamento.salvar()}" update="@form" />
                        <p:commandButton value="Cancelar" icon="ui-icon-arrowreturnthick-1-w" actionListener="#{managerLancamento.redirect('indexLancamento.xhtml')}" immediate="true"/>

                    </div>

                    <p:dialog modal="true" id="dlgProtocolo" widgetVar="dlgProtocolo" dynamic="true" header="Protocolo">
                        <h:panelGrid columns="2" columnClasses="columnLabel,columnData" styleClass="textAlignRight"> 
                            <h:outputLabel value="Código : "/>
                            <h:outputText value="#{managerLancamento.protocolo.id}" />
                            <h:outputLabel value="Data : "/>
                            <h:outputText value="#{managerLancamento.protocolo.dataCad}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                            <h:outputLabel value="Cliente : "/>
                            <h:outputText value="#{managerLancamento.protocolo.cliente.nome}" />
                            <h:outputLabel value="Forma de pagamento: "/>
                            <h:outputText value="#{managerLancamento.protocolo.formasPagamento.nome}" />


                            <h:outputLabel value="Serviços do Protocolo" style="font-weight: bold;"/>
                            <h:outputLabel value=" " style="font-weight: bold;"/>
                        </h:panelGrid>

                        <table style="width:100%">
                            <tbody style="background-color: #5277A9; color: #ffffff; ">
                                <td style="font-weight: bold; text-align: center;">
                                    Ato Item
                                </td>
                                <td style="font-weight: bold; text-align: center;">
                                    Cartório
                                </td>
                                <td style="font-weight: bold; text-align: center;">
                                    Fermojupi
                                </td>
                                <td style="font-weight: bold; text-align: center;" >
                                    Valor
                                </td>

                            </tbody>
                            <ui:repeat value="#{managerLancamento.protocolo.servicoProtocolos}" var="servico">
                                <tr>
                                    <td style="text-align: left;">
                                        <h:outputLabel value="#{servico.atoItem.codigo}" /> - 
                                        <h:outputLabel value="#{servico.atoItem.descricao}" /></td>
                                    <td style="text-align: center;"><h:outputLabel value="#{servico.valorCartorio}" /></td>
                                    <td style="text-align: center;" ><h:outputLabel value="#{servico.valorFermojupi}" /></td>
                                    <td style="text-align: center;"><h:outputLabel value="#{servico.valor}" /></td>
                                </tr>
                            </ui:repeat>

                        </table>



                    </p:dialog>


                    <p:dialog modal="true" id="dlgPagamento" widgetVar="dlgPagamento" dynamic="true" header="Pagamento">
                        <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="columnLabel,columnData"  > 
                            <h:outputLabel value="Código : "/>
                            <h:outputText value="#{managerLancamento.pagamento.id}" />

                            <h:outputLabel value="Data : "/>
                            <h:outputText value="#{managerLancamento.pagamento.dataPag}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                            <h:outputLabel value="Título : "/>
                            <h:outputText value="#{managerLancamento.pagamento.titulo}" />
                            <h:outputLabel value="Interessado : "/>
                            <h:outputText value="#{managerLancamento.pagamento.interessado}" />
                            <h:outputLabel value="Descrição : "/>
                            <h:outputText value="#{managerLancamento.pagamento.descricao}" />


                        </h:panelGrid>
                    </p:dialog>


                </p:panel>

            </h:form>
        </ui:define>
    </ui:composition>
</html>